package jvm.stack;

/**
 * @author 马迪迪
 * @description: TODO
 * @data 2025年01月14日23时41分
 */
public class 局部变量影响现场安全问题2 {

    public static void main(String[] args) {
        Thread one = new Thread(new Thread_Two_To_One());
        Thread two = new Thread(new Thread_Two_To_Two());
        Thread three = new Thread(new Thread_Two_To_Three());
        one.run();
        two.run();
        three.run();
    }


    //    方法内的局部变量
    static void m1() {
        StringBuilder sb = new StringBuilder();
        sb.append(1);
        sb.append(2);
        sb.append(3);
        System.out.println("m1" + sb.toString());
    }

    //
    static void m2(StringBuilder sb) {
        sb.append(1);
        sb.append(2);
        sb.append(3);
        System.out.println("m2" + sb.toString());
    }

    static StringBuilder m3() {
        StringBuilder sb = new StringBuilder();
        sb.append(1);
        sb.append(2);
        sb.append(3);
        return sb;
    }
}


class Thread_Two_To_One implements Runnable {
    public void run() {
        局部变量影响现场安全问题2.m1();
    }
}

class Thread_Two_To_Two implements Runnable {
    public void run() {
        StringBuilder sb = new StringBuilder();
        sb.append(4);
        sb.append(5);
        sb.append(6);
        局部变量影响现场安全问题2.m2(sb);
    }
}

class Thread_Two_To_Three implements Runnable {
    public void run() {
        System.out.println("m3" + 局部变量影响现场安全问题2.m3().toString());
    }
}